/*
 * jxUtils Project (2013, 2014)
 * 
 * by Denilson Edinaldo Pinto
 * 
 * LGPL
 * Copyright (C) 2014
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.jxUtils.file.type;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.jxUtils.collection.CollectionUtil;
import org.jxUtils.file.type.document.adobe.POST_SCRIPT;
import org.jxUtils.file.type.simpleText.ACTION_SCRIPT;
import org.jxUtils.file.type.simpleText.ADA;
import org.jxUtils.file.type.simpleText.AIML;
import org.jxUtils.file.type.simpleText.ASM;
import org.jxUtils.file.type.simpleText.ASP;
import org.jxUtils.file.type.simpleText.AUTOIT;
import org.jxUtils.file.type.simpleText.BASH;
import org.jxUtils.file.type.simpleText.BATCH;
import org.jxUtils.file.type.simpleText.C;
import org.jxUtils.file.type.simpleText.CAML;
import org.jxUtils.file.type.simpleText.CMAKE;
import org.jxUtils.file.type.simpleText.COBOL;
import org.jxUtils.file.type.simpleText.CPP;
import org.jxUtils.file.type.simpleText.CS;
import org.jxUtils.file.type.simpleText.CSS;
import org.jxUtils.file.type.simpleText.CSV;
import org.jxUtils.file.type.simpleText.D;
import org.jxUtils.file.type.simpleText.DIFF;
import org.jxUtils.file.type.simpleText.FORTRAN;
import org.jxUtils.file.type.simpleText.HASKELL;
import org.jxUtils.file.type.simpleText.HTML;
import org.jxUtils.file.type.simpleText.INI;
import org.jxUtils.file.type.simpleText.INNO;
import org.jxUtils.file.type.simpleText.JAVA;
import org.jxUtils.file.type.simpleText.JAVA_SCRIPT;
import org.jxUtils.file.type.simpleText.JSP;
import org.jxUtils.file.type.simpleText.KIX;
import org.jxUtils.file.type.simpleText.LISP;
import org.jxUtils.file.type.simpleText.LUA;
import org.jxUtils.file.type.simpleText.MAKE_FILE;
import org.jxUtils.file.type.simpleText.MATLAB;
import org.jxUtils.file.type.simpleText.NFO;
import org.jxUtils.file.type.simpleText.NORMAL_TEXT;
import org.jxUtils.file.type.simpleText.NSIS;
import org.jxUtils.file.type.simpleText.PASCAL;
import org.jxUtils.file.type.simpleText.PERL;
import org.jxUtils.file.type.simpleText.PHP;
import org.jxUtils.file.type.simpleText.POWER_SHELL;
import org.jxUtils.file.type.simpleText.PROPERTIES;
import org.jxUtils.file.type.simpleText.PYTHON;
import org.jxUtils.file.type.simpleText.R;
import org.jxUtils.file.type.simpleText.RC;
import org.jxUtils.file.type.simpleText.RUBY;
import org.jxUtils.file.type.simpleText.SCHEME;
import org.jxUtils.file.type.simpleText.SMALL_TALK;
import org.jxUtils.file.type.simpleText.SQL;
import org.jxUtils.file.type.simpleText.SRT;
import org.jxUtils.file.type.simpleText.SSA;
import org.jxUtils.file.type.simpleText.TCL;
import org.jxUtils.file.type.simpleText.TEX;
import org.jxUtils.file.type.simpleText.VB;
import org.jxUtils.file.type.simpleText.VERILOG;
import org.jxUtils.file.type.simpleText.VHDL;
import org.jxUtils.file.type.simpleText.XML;
import org.jxUtils.file.type.simpleText.YAML;

/**
 * @author Denilson Edinaldo Pinto
 * @project jxUtils
 * @package org.jxUtils.file.type
 * @date 22/05/2013 - 20:28:10
 */
public final class SimpleTextType implements CollectionFileType {
	
	public static final Set<FileTypeFace> TYPES = new HashSet<FileTypeFace>();
	
	static {
		
		TYPES.add(new ACTION_SCRIPT());
		TYPES.add(new ADA());
		TYPES.add(new AIML());
		TYPES.add(new ASM());
		TYPES.add(new ASP());
		TYPES.add(new AUTOIT());
		TYPES.add(new BASH());
		TYPES.add(new BATCH());
		TYPES.add(new C());
		TYPES.add(new CAML());
		TYPES.add(new CMAKE());
		TYPES.add(new COBOL());
		TYPES.add(new CPP());
		TYPES.add(new CS());
		TYPES.add(new CSS());
		TYPES.add(new CSV());
		TYPES.add(new D());
		TYPES.add(new DIFF());
		TYPES.add(new FORTRAN());
		TYPES.add(new HASKELL());
		TYPES.add(new HTML());
		TYPES.add(new INI());
		TYPES.add(new INNO());
		TYPES.add(new JAVA());
		TYPES.add(new JAVA_SCRIPT());
		TYPES.add(new JSP());
		TYPES.add(new KIX());
		TYPES.add(new LISP());
		TYPES.add(new LUA());
		TYPES.add(new MAKE_FILE());
		TYPES.add(new MATLAB());
		TYPES.add(new NFO());
		TYPES.add(new NORMAL_TEXT());
		TYPES.add(new NSIS());
		TYPES.add(new PASCAL());
		TYPES.add(new PERL());
		TYPES.add(new PHP());
		TYPES.add(new POST_SCRIPT());
		TYPES.add(new POWER_SHELL());
		TYPES.add(new PROPERTIES());
		TYPES.add(new PYTHON());
		TYPES.add(new R());
		TYPES.add(new RC());
		TYPES.add(new RUBY());
		TYPES.add(new SCHEME());
		TYPES.add(new SMALL_TALK());
		TYPES.add(new SQL());
		TYPES.add(new SRT());
		TYPES.add(new SSA());
		TYPES.add(new TCL());
		TYPES.add(new TEX());
		TYPES.add(new VB());
		TYPES.add(new VERILOG());
		TYPES.add(new VHDL());
		TYPES.add(new XML());
		TYPES.add(new YAML());
	}
	
	@Override
	public boolean contains(final String extension) {
	
		return containsInAny(extension);
	}
	
	@Override
	public String extensionsToString() {
	
		final StringBuilder extensions = new StringBuilder();
		
		//
		for(final FileTypeFace type : getTypes()) {
			
			extensions.append(type.toString() + " ");
		}
		
		return extensions.toString().trim();
	}
	
	@Override
	public String[] getExtensions() {
	
		final List<String> extensions = getAllExtensions();
		
		final String[] strExtensions = new String[extensions.size()];
		
		return extensions.toArray(strExtensions);
	}
	
	@Override
	public String[] getExtensionsWithoutPoint() {
	
		final List<String> extensionsAux = getAllExtensions();
		
		//
		for(final String extension : getAllExtensions()) {
			
			extensionsAux.add(extension.substring(1));
		}
		
		final String[] strExtensions = new String[extensionsAux.size()];
		
		return extensionsAux.toArray(strExtensions);
	}
	
	/**
	 * @param extension
	 */
	public static boolean containsInAny(final String extension) {
	
		return FileType.containsInAny(extension, getTypes());
	}
	
	/**
	 * @return all extensions
	 */
	public static List<String> getAllExtensions() {
	
		return FileType.getAllExtensions(getTypes());
	}
	
	/**
	 * @return the types
	 */
	public static List<FileTypeFace> getTypes() {
	
		return CollectionUtil.clone(TYPES);
	}
}
